<template>
  <v-dialog :title="title" :close-on-click-modal="false" v-model="visible" >
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method==='view'" label-width="120px">
      <el-row >
        <!-- <el-col :span="12">
          <el-form-item label="项目id" prop="project.id" :rules="[
                 ]">
            <GridSelect title="选择项目id" labelName='projectName' labelValue='id' v-model="inputForm.project.id" :limit="1" :columns="[
            {
              prop: 'projectNo',
              label: '项目编号'
            },
            {
              prop: 'projectName',
              label: '项目名称'
            }
            ]" :searchs="[
            {
              prop: 'projectNo',
              label: '项目编号'
            },
            {
              prop: 'projectName',
              label: '项目名称'
            }
            ]" :api="projectMainService">
            </GridSelect>
          </el-form-item>
        </el-col> -->
        <el-col :span="12">
          <el-form-item label="甲方" prop="correspondent.id" :rules="[
                 ]">
            <GridSelect title="选择甲方" labelName='companyName' labelValue='id' v-model="inputForm.correspondent.id" :limit="1" :columns="[
           
            {
              prop: 'companyName',
              label: '单位名称'
            }
            ]" :searchs="[
            {
              prop: 'companyName',
              label: '单位名称'
            }
            ]" :api="correspondentService">
            </GridSelect>
          </el-form-item>
        </el-col>
      
        <el-col :span="12">
          <el-form-item label="预计合同额(元)" prop="contractAmt" :rules="[
                 ]">
            <el-input v-model="inputForm.contractAmt" placeholder="请填写预计合同额"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="预计利润(元)" prop="contractProfit" :rules="[
                 ]">
            <el-input v-model="inputForm.contractProfit" placeholder="请填写预计利润"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="集团内/外" prop="groupInternalExternal" :rules="[
                 ]">
            <el-select v-model="inputForm.groupInternalExternal" placeholder="请选择" style="width: 100%;">
              <el-option v-for="item in $dictUtils.getDictList('group_internal_external')" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
          <el-col :span="24">
          <el-form-item label="项目概况" prop="projectProfile" :rules="[
                 ]">
            <el-input v-model="inputForm.projectProfile" placeholder="请填写项目概况"  type='textarea'  :rows='6'></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false" icon="circle-close">关闭</el-button>
        <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" icon="circle-check" v-noMoreClick>确定</el-button>
      </span>
    </template>
  </v-dialog>
</template>

<script>
import GridSelect from '@/components/gridSelect'
import projectFollowService from '@/api/follow/projectFollowService'
import projectMainService from '@/api/project/projectMainService'
import correspondentService from '@/api/correspondent/correspondentService'
export default {
  data() {
    return {
      title: '',
      method: '',
      visible: false,
      loading: false,
      projectMainService: projectMainService,
      correspondentService: correspondentService,
      inputForm: {
        id: '',
        project: {
          id: ''
        },
        correspondent: {
          id: ''
        },
        projectProfile: '',
        contractAmt: '',
        contractProfit: '',
        groupInternalExternal: ''
      }
    }
  },
  components: {
    GridSelect
  },
  created() {
  },
  methods: {
    init(method, id,correspondentId) {
      this.method = method
    
      if (method === 'add') {
        this.inputForm.id = '';
        this.inputForm.project.id =id;
       this.inputForm.correspondent.id=correspondentId
        this.title = `新建项目跟进`
      } else if (method === 'edit') {
         this.inputForm.id = id
        this.title = '修改项目跟进'
      } else if (method === 'view') {
         this.inputForm.id = id
        this.title = '查看项目跟进'
      }
      this.visible = true
      this.loading = false
      this.$nextTick(() => {
        this.$refs.inputForm.resetFields()
        if (method === 'edit' || method === 'view') { // 修改或者查看
          this.loading = true
          projectFollowService.queryById(this.inputForm.id).then((data) => {
            this.inputForm = this.recover(this.inputForm, data)
            this.loading = false
          })
        }
      })
    },
    // 表单提交
    doSubmit() {
      this.$refs['inputForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          projectFollowService.save(this.inputForm).then((data) => {
            this.visible = false
            this.$message.success(data)
            this.$emit('refreshDataList')
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>

  
